package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.TransportTaskEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 接运任务表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class TransportTaskProvider {

    /**
     * 增加TransportTask
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertTransportTask(@Param("entity") TransportTaskEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" transport_task ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" transport_purpose_code ", " #{entity.transportPurposeCode,jdbcType=SMALLINT} ");
                VALUES(" appointment_time ", " #{entity.appointmentTime,jdbcType=TIMESTAMP} ");
                VALUES(" transport_car_type_code ", " #{entity.transportCarTypeCode,jdbcType=SMALLINT} ");
                VALUES(" transport_car_id ", " #{entity.transportCarId,jdbcType=INTEGER} ");
                VALUES(" transport_car_no ", " #{entity.transportCarNo,jdbcType=VARCHAR} ");
                VALUES(" driver_user_id ", " #{entity.driverUserId,jdbcType=INTEGER} ");
                VALUES(" driver_user_name ", " #{entity.driverUserName,jdbcType=VARCHAR} ");
                VALUES(" driver_user_telephone ", " #{entity.driverUserTelephone,jdbcType=VARCHAR} ");
                VALUES(" transport_place ", " #{entity.transportPlace,jdbcType=VARCHAR} ");
                VALUES(" transport_linkman ", " #{entity.transportLinkman,jdbcType=VARCHAR} ");
                VALUES(" transport_telephone ", " #{entity.transportTelephone,jdbcType=VARCHAR} ");
                VALUES(" departure_time ", " #{entity.departureTime,jdbcType=TIMESTAMP} ");
                VALUES(" return_time ", " #{entity.returnTime,jdbcType=TIMESTAMP} ");
                VALUES(" process_state_code ", " #{entity.processStateCode,jdbcType=TINYINT} ");

                if (entity.getAsEmptyCar() != null) {
                    VALUES(" as_empty_car ", " #{entity.asEmptyCar,jdbcType=TINYINT} ");
                }

                VALUES(" transport_distance ", " #{entity.transportDistance,jdbcType=DECIMAL} ");
                VALUES(" rule_number ", " #{entity.ruleNumber,jdbcType=DECIMAL} ");
                VALUES(" rule_unit ", " #{entity.ruleUnit,jdbcType=VARCHAR} ");
                VALUES(" rule_code ", " #{entity.ruleCode,jdbcType=VARCHAR} ");
                VALUES(" rule_remark ", " #{entity.ruleRemark} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" random_code ", " #{entity.randomCode,jdbcType=VARCHAR} ");
                VALUES(" charge_id ", " #{entity.chargeId,jdbcType=INTEGER} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改TransportTask
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateTransportTask(@Param("entity") TransportTaskEntity entity) {
        return new SQL() {
            {
                UPDATE(" transport_task ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" transport_purpose_code = #{entity.transportPurposeCode,jdbcType=SMALLINT} ");
                SET(" appointment_time = #{entity.appointmentTime,jdbcType=TIMESTAMP} ");
                SET(" transport_car_type_code = #{entity.transportCarTypeCode,jdbcType=SMALLINT} ");
                SET(" transport_car_id = #{entity.transportCarId,jdbcType=INTEGER} ");
                SET(" transport_car_no = #{entity.transportCarNo,jdbcType=VARCHAR} ");
                SET(" driver_user_id = #{entity.driverUserId,jdbcType=INTEGER} ");
                SET(" driver_user_name = #{entity.driverUserName,jdbcType=VARCHAR} ");
                SET(" driver_user_telephone = #{entity.driverUserTelephone,jdbcType=VARCHAR} ");
                SET(" transport_place = #{entity.transportPlace,jdbcType=VARCHAR} ");
                SET(" transport_linkman = #{entity.transportLinkman,jdbcType=VARCHAR} ");
                SET(" transport_telephone = #{entity.transportTelephone,jdbcType=VARCHAR} ");
                SET(" departure_time = #{entity.departureTime,jdbcType=TIMESTAMP} ");
                SET(" return_time = #{entity.returnTime,jdbcType=TIMESTAMP} ");
                SET(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");

                if (entity.getAsEmptyCar() != null) {
                    SET(" as_empty_car = #{entity.asEmptyCar,jdbcType=TINYINT} ");
                }

                SET(" transport_distance = #{entity.transportDistance,jdbcType=DECIMAL} ");
                SET(" rule_number = #{entity.ruleNumber,jdbcType=DECIMAL} ");
                SET(" rule_unit = #{entity.ruleUnit,jdbcType=VARCHAR} ");
                SET(" rule_code = #{entity.ruleCode,jdbcType=VARCHAR} ");
                SET(" rule_remark = #{entity.ruleRemark} ");
                SET(" remark = #{entity.remark} ");
                SET(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                SET(" charge_id = #{entity.chargeId,jdbcType=INTEGER} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询TransportTask列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listTransportTask(@Param("entity") TransportTaskEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,transport_purpose_code,appointment_time,transport_car_type_code,transport_car_id,transport_car_no,driver_user_id,driver_user_name,driver_user_telephone,transport_place,transport_linkman,transport_telephone,departure_time,return_time,process_state_code,as_empty_car,transport_distance,rule_number,rule_unit,rule_code,rule_remark,remark,random_code,charge_id,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" transport_task ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getTransportPurposeCode() != null) {
                    WHERE(" transport_purpose_code = #{entity.transportPurposeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getAppointmentTime() != null) {
                    WHERE(" appointment_time = #{entity.appointmentTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getTransportCarTypeCode() != null) {
                    WHERE(" transport_car_type_code = #{entity.transportCarTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getTransportCarId() != null) {
                    WHERE(" transport_car_id = #{entity.transportCarId,jdbcType=INTEGER} ");
                }

                if (entity.getTransportCarNo() != null) {
                    WHERE(" transport_car_no = #{entity.transportCarNo,jdbcType=VARCHAR} ");
                }

                if (entity.getDriverUserId() != null) {
                    WHERE(" driver_user_id = #{entity.driverUserId,jdbcType=INTEGER} ");
                }

                if (entity.getDriverUserName() != null) {
                    WHERE(" driver_user_name = #{entity.driverUserName,jdbcType=VARCHAR} ");
                }

                if (entity.getDriverUserTelephone() != null) {
                    WHERE(" driver_user_telephone = #{entity.driverUserTelephone,jdbcType=VARCHAR} ");
                }

                if (entity.getTransportPlace() != null) {
                    WHERE(" transport_place = #{entity.transportPlace,jdbcType=VARCHAR} ");
                }

                if (entity.getTransportLinkman() != null) {
                    WHERE(" transport_linkman = #{entity.transportLinkman,jdbcType=VARCHAR} ");
                }

                if (entity.getTransportTelephone() != null) {
                    WHERE(" transport_telephone = #{entity.transportTelephone,jdbcType=VARCHAR} ");
                }

                if (entity.getDepartureTime() != null) {
                    WHERE(" departure_time = #{entity.departureTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getReturnTime() != null) {
                    WHERE(" return_time = #{entity.returnTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getProcessStateCode() != null) {
                    WHERE(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");
                }

                if (entity.getAsEmptyCar() != null) {
                    WHERE(" as_empty_car = #{entity.asEmptyCar,jdbcType=TINYINT} ");
                }

                if (entity.getTransportDistance() != null) {
                    WHERE(" transport_distance = #{entity.transportDistance,jdbcType=DECIMAL} ");
                }

                if (entity.getRuleNumber() != null) {
                    WHERE(" rule_number = #{entity.ruleNumber,jdbcType=DECIMAL} ");
                }

                if (entity.getRuleUnit() != null) {
                    WHERE(" rule_unit = #{entity.ruleUnit,jdbcType=VARCHAR} ");
                }

                if (entity.getRuleCode() != null) {
                    WHERE(" rule_code = #{entity.ruleCode,jdbcType=VARCHAR} ");
                }

                if (entity.getRuleRemark() != null) {
                    WHERE(" rule_remark = #{entity.ruleRemark} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getRandomCode() != null) {
                    WHERE(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                }

                if (entity.getChargeId() != null) {
                    WHERE(" charge_id = #{entity.chargeId,jdbcType=INTEGER} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}